import request from '@/util/request'
import store from '@/vuex/store'
import config from '@/config/config'

//获取授权码列表
export function getPermissionData(list) {
    const value = {
        appKey: '',
        appFlag: 2,
        token: store.getters.token,
        versionCode: 0,
        param: JSON.stringify(list)
    }
    return request({
        url: 'permission/permissionApi/getPermissionData.do',
        method: 'post',
        data: value
    })
}

//添加授权码
export function addPermissionData(list) {
    return request({
        url: 'permission/permissionApi/addPermissionData.do',
        method: 'post',
        data: {
            token: store.getters.token,
            createNum: list.createNum,
            permissionType: list.permissionType,
            permissionEffective: list.permissionEffective,
        }
    })
}


//发放授权码
export function editPermissionGrantState(list) {
    const value = {
        appKey: '',
        appFlag: 2,
        token: store.getters.token,
        versionCode: 0,
        param: JSON.stringify(list)
    }
    return request({
        url: 'permission/permissionApi/editPermissionGrantState.do',
        method: 'post',
        data: value
            /* data: {
                permissionL: JSON.stringify(list),
                permissionCompany: JSON.stringify(permissionCompany),
                token: store.getters.token,
            } */
    })
}


//删除授权码
export function delPermission(list) {
    return request({
        url: 'permission/permissionApi/editPermissionGrantState.do',
        method: 'post',
        data: {
            permissionL: JSON.stringify(list),
            token: store.getters.token,
        }
    })
}

//获取申请试用信息列表
export function getApplyInfo(list) {
    var params = {
        pageSize: list.pageSize,
        currentPage: list.currentPage,
        phone: list.phone,
        sendState: list.sendState,
        time: list.time
    }
    const value = {
        appKey: '',
        appFlag: 2,
        token: store.getters.token,
        versionCode: 0,
        param: JSON.stringify(params)
    }
    return request({
        url: 'apply/ApplyApi/getApplyInfo.do',
        method: 'post',
        data: value
    })
}
//通过授权码Id查询
export function getPermissionById(permissionId) {
    const value = {
        appKey: '',
        appFlag: 2,
        token: store.getters.token,
        versionCode: 0,
        param: permissionId
    }
    return request({
        url: 'permission/permissionApi/getPermissionById.do',
        method: 'post',
        data: value
    })
}
//通过单位Id修改
export function editInfo(list) {
    var params = {
        id: list.id,
        company: list.company
    }
    const value = {
        appKey: '',
        appFlag: 2,
        token: store.getters.token,
        versionCode: 0,
        param: JSON.stringify(params)
    }
    return request({
        url: 'permission/permissionApi/editById.do',
        method: 'post',
        data: value
    })
}

//导出Excel
export function exportToExcel(list) {
    const value = {
        appKey: '',
        appFlag: 2,
        token: store.getters.token,
        versionCode: 0,
        param: JSON.stringify(list)
    }
    return request({
        url: 'permission/permissionApi/exportPermissionXls.do',
        method: 'post',
        data: value
    })
}